#ifndef __HTTP_NET_CONFIG_SERVER__H_
#define __HTTP_NET_CONFIG_SERVER__H_

#include <stdbool.h>
#include "cmsis_os2.h"

#define RECV_BUFFER_SIZE 1024
#define SEND_BUFFER_SIZE 512

#define MAX_FORMDATA_LENGTH 300

struct HttpRequest
{
    uint16_t bodyStartPos;
    uint16_t requestSize;
    char buffer[RECV_BUFFER_SIZE];
    uint16_t bufferPos;
};

typedef void (*HttpRequestHandler)(int fd, struct HttpRequest *req);
struct RequestMapper
{
    const char *action;
    HttpRequestHandler handler;
};

int RunHTTPServer(struct RequestMapper *mapper, uint8_t mapperSize);

void ShutdownHttpServer(void);

char* GetAction(struct HttpRequest *req);
char* GetHeaderValue(struct HttpRequest *req, const char* name);

bool GetFormPara(struct HttpRequest *req, const char *name, char* buff, uint16_t buffSize);

void ResponseError(int fd, uint16_t errCode);

void HttpResponse(int fd, const char *format, ...);

#endif